function getValueOfVariable(str)
{
	var reM = /\$[\w]+|\$\([\w]+\)/gi;
	var arrMactches = str.match(reM)
	if(arrMactches == null){
		return str;
	}
	for (var i=0;i < arrMactches.length ; i++)
	{ 
		var reM2 = /[\w]+/;
		var varName =  reM2.exec(arrMactches[i]);
		var varValue = getCookie(varName);
		if(varValue != null){
			str=str.replace(arrMactches[i],varValue);
		}else{
			str=str.replace(arrMactches[i],"");
		}
	}
	return str;	
}






function setCookie(name,value){
	value = value.replaceAll("\"","'");
	value = value.replaceAll("\r\n","");
	value = value.replaceAll("\t","");
	
    value = getValueOfVariable(value);
	if(value==null){
		
    	value = "";
	}
	var re = new RegExp(name+"===[^;]*"+";");	
	if(re.test(variable)){
		variable = variable.replace(re,name+"==="+value+";");

	}else{
		
		variable = variable+name+"==="+value+";";	
	}
	

}

function getCookie(name)      
{
	var re = new RegExp(name+"===([^;]*)"+";");
	var ii = re.exec(variable);
	if(ii != null &&ii.length == 2){
		return ii[1];
	}
	return null;
}

function setVariable(name,value){
	return setCookie(name,value);
}
function getVariable(name){
	return getCookie(name);
}
function clearVariable(){
	variable="null;";
}

String.prototype.replaceAll = function(s1,s2){
	return this.replace(new RegExp(s1,"gm"),s2);
}
//alert(variable);
